<?php
$goods_id = isset($_GET['goods_id']) ? intval($_GET['goods_id']) : 0;
if (empty($goods_id)) {
    exit('商品不存在或者已删除');
}
$goodsCart = [];
session_start();
if (isset($_SESSION['carts'])) $goodsCart = $_SESSION['carts'];

if (isset($goodsCart[$goods_id])) {
    $goodsCart[$goods_id]['num'] += 1;
} else {
    $goodsCart[$goods_id] = [
        'num' => 1
    ];
}
echo '添加商品成功';
$_SESSION['carts'] = $goodsCart;